﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using PreeRegisterModel;
using System.Collections.Specialized;
using PreeRegisterBLL;
using PreeRegisterBLL.Security;

namespace PreeRegister_WebAPI.Controllers
{
    public class identityController : ApiController
    {
        [HttpPost]
        /// <summary>
        /// 获取诊疗ID
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel get(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                IdentityGetResponseModel identityGetResponseModel = new IdentityGetResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "identity|get", ref head_json, ref body_json, ref ErrMsg))
                {

                    identityGetResponseModel.code = "0";
                    identityGetResponseModel.msg = "获取诊疗ID失败:" + ErrMsg;

                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.IdentityGetResponseModel(identityGetResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("identity|get|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                IdentityGetRequestModel identityGetRequestModel = csSerialize.identityGetRequestModel(body_json);

                //查询诊疗ID情况
                identityGetResponseModel = IdentityGetBLL.IdentityGet(identityGetRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.IdentityGetResponseModel(identityGetResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("identity|get|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                IdentityGetResponseModel identityGetResponseModel = new IdentityGetResponseModel();

                identityGetResponseModel.code = "0";
                identityGetResponseModel.msg = err.Message;

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.IdentityGetResponseModel(identityGetResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("identity|get|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }


    }
}
